// admissStu.js
var app = getApp(); 
var url = app.globalData.http + "fromStudent.do";
var utils=require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:0,
    curPage:1,
    hasMoreData: true,
    id: 0,
    recordList:[],
    myClassMemInfo: {
     studentName : "",
     studentPhone : "",
     studentNo : "",
     school : "",
     gradeName: "",
     sex : "0",
     address : "",
     email : "",
     studentAnalysis : "",
     className: "",
     parents: [
       {
         id:0,
         parentName :"",
         parentCall : "",
         phone : "",
         memberId : 0
      }
     ],
    analysis :[
      {
        studentId : 0,
        subjectId :0,
        score :0
      }
    ]
    }
  },
 // tab切换
  remarkTap: function (e) {
    console.log(e.currentTarget.dataset.id);
    this.setData({
      currentTab: e.currentTarget.dataset.id
    });
  },

  //修改信息
  admissAdd: function(e){
    var that = this;
    var id = that.data.id;
    wx.navigateTo({
      url: "/pages/admissAdd/admissAdd?id="+id
    })
  },

  //新增跟进记录
  addCommunicate: function(e){
    var that = this;
    var id = that.data.id;
    wx.navigateTo({
      url: "/pages/admissWrite/admissWrite?id="+id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("意向学员==跟进信息==",options);
    var that = this;
    wx.request({
      url: url,
      header: {
        'content-type': 'application/json'
      },
      data:{
        studentId : parseInt(options.id),
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        var code = res.data.code;
        console.log("学员详细信息请求成功数据==",res.data)
        if(code == 100){
          that.setData({
            id: options.id,
            studentName:res.data.data.studentName,
            studentPhone: res.data.data.studentPhone,
            studentNo: res.data.data.studentNo,
            school: res.data.data.school,
            gradeName: res.data.data.gradeName,
            sex: res.data.data.sex,
            address: res.data.data.address,
            email: res.data.data.email,
            studentAnalysis: res.data.data.studentAnalysis,
            parents: res.data.data.parents,
            analysis :res.data.data.analysis,
            className: res.data.data.className
          })
        }
        if(code == 200){
          that.setData({
            codeTxt: "数据为空"
          })
        }
        if(code == 300){
          codeTxt: "哇哦~数据异常"
        }
        
        console.log("studentName==",that.data.studentName)
      }
    });

    wx.request({
      url: app.globalData.http + "selectCommunication.do",
      header: {
        'content-type': 'application/json'
      },
      data:{
        studentId : parseInt(options.id),
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        console.log("意向学院==沟通记录==",res.data);
        var code = res.data.code;
        if(code == 100){
          var list = res.data.data;
          var length = list.length;
          for(var i = 0; i < length; i++){
          list[i].updateDate =utils.formatTime( new Date(list[i].updateDate));
          }
          that.setData({
            recordList: list,
          })
        }
        if(code == 200 || code == 300){
          return
        }  
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})